<template>
  <div class="cart">
    <h2>我的购物车</h2>
    <p>
      <i>请添加一些商品到购物车</i>
    </p>
    <ul>
      <li v-for="item in cartStore.cartProducts" :key="item.id">
        <button @click="cartStore.changeCartNum(item)" v-if="item.num">
          -
        </button>
        {{ item.title }} - {{ item.price }} × {{ item.num }}
      </li>
    </ul>
    <p>商品总价： {{ cartStore.totalPrice }}</p>
    <p>
      <button @click="cartStore.checkOut(cartStore.totalPrice)">结算</button>
    </p>
    <p v-show="cartStore.checkoutStatus">结算{{ cartStore.checkoutStatus }}.</p>
  </div>
</template>

<script lang="ts" setup>
import { useCartStore } from '../store/cart'
const cartStore = useCartStore()
</script>
